package com.example.demo.api.controller;

import com.example.demo.app.service.StudentService;
import com.example.demo.app.service.TeacherService;
import com.example.demo.domain.entity.Student;
import com.example.demo.domain.entity.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;
    @GetMapping("/{id}")
    public Teacher get(@PathVariable("id") Integer id){
        return teacherService.queryTeacherById(id);
    }

    @GetMapping("/list")
    public List<Teacher> get(){
        return teacherService.queryTeacherList();
    }

    @PostMapping
    public Integer add(@RequestBody Teacher teacher){
        teacherService.addTeacher(teacher);
        return teacher.getId();
    }

    @PutMapping
    public Integer save(@RequestBody Teacher teacher){
        return teacherService.saveTeacher(teacher);
    }

    @PostMapping("/{id}")
    public Integer delete(@PathVariable("id") Integer id){
        return teacherService.deleteTeacherById(id);
    }
}
